/******************************************************************************

	COPYRIGHT(C) JONAS 'SORTIE' TERMANSEN 2010.

	This file is part of Maxsi Engine.

	Maxsi Engine is free software: you can redistribute it and/or modify it
	under the terms of the GNU Lesser General Public License as published by
	the Free Software Foundation, either version 3 of the License, or (at your
	option) any later version.

	Maxsi engine is distributed in the hope that it will be useful, but WITHOUT
	ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
	FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
	for more details.

	You should have received a copy of the GNU Lesser General Public License
	along with Maxsi Engine. If not, see <http://www.gnu.org/licenses/>.

	MaxsiEngine.dll
	A general purpose C++ library for the Maxsi Technology Project.

	MaxsiWindowW32.cpp
	Implements the MaxsiWindowSystem using the W32 platform.

******************************************************************************/


#include "MaxsiEngine.h"

#ifdef Maxsi_Support_W32

BeginMaxsiNamespace

MaxsiWindowSystemW32::MaxsiWindowSystemW32()
{
	
}

MaxsiWindowSystemW32::~MaxsiWindowSystemW32()
{
	if ( ControlSystem ) { DeleteControlSystem(ControlSystem); }
}

MaxsiControlSystem* MaxsiWindowSystemW32::GetControlSystem()
{
	if ( ControlSystem == NULL ) { ControlSystem = CreateControlSystem(); }

	if ( ControlSystem ) { ControlSystem->SetWindowSystem(this); }

	return ControlSystem;
}

MaxsiControlSystem* MaxsiWindowSystemW32::CreateControlSystem()
{
	return new MaxsiControlSystemW32;
}

bool MaxsiWindowSystemW32::DeleteControlSystem(MaxsiControlSystem* ControlSystem)
{
	delete (MaxsiControlSystemW32*)ControlSystem;
	return true;
}

int MaxsiWindowSystemW32::Initialize(int* argc, char*** argv)
{
	return 1;
}

int MaxsiWindowSystemW32::MainLoop()
{
	MSG		msg			=	{0};
	BOOL	bRet		=	FALSE;

	// Begin the mainloop
	while( (bRet = GetMessage( &msg, NULL, 0, 0 )) != 0)
	{ 
		if ( bRet == -1 ) { break; }

		TranslateMessage(&msg);
		DispatchMessage(&msg); 
	}

	return (int)msg.wParam;
}

MaxsiHandle MaxsiWindowSystemW32::CreateWindow(MaxsiHandle Parent, int Width, int Height, int Left, int Top, MESTR* Title)
{
	return (MaxsiHandle)CreateWindowM(
        _MESTR("MaxsiWindowSystemW32Window"),
        Title,
        (WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX ),
        Left, Top,
        Width, Height,
        (HWND)Parent, NULL, GetModuleHandle(NULL), NULL );
}

bool MaxsiWindowSystemW32::ShowWindow(MaxsiHandle Window)
{
	return (::ShowWindow((HWND)Window, SW_SHOW) != FALSE);
}

bool MaxsiWindowSystemW32::HideWindow(MaxsiHandle Window)
{
	return (::ShowWindow((HWND)Window, SW_HIDE) != FALSE);
}

MaxsiHandle MaxsiWindowSystemW32::CreatePictureBufferFromFile(MESTR* FileName)
{
	return NULL; // MAXSI_ERROR_NOT_IMPLEMENTED
}

bool MaxsiWindowSystemW32::DeletePictureBuffer(MaxsiHandle PictureBuffer)
{
	return false;
}

bool MaxsiWindowSystemW32::SetWindowIcon(MaxsiHandle Window, MaxsiHandle Icon)
{
	return false; // MAXSI_ERROR_NOT_IMPLEMENTED
}

int MaxsiWindowSystemW32::MoveWindowControl(MaxsiHandle Parent, MaxsiHandle Control, int Top, int Left, int Width, int Height, bool UnusedInLinux)
{
	return (MoveWindow((HWND)Control, Top, Left, Width, Height, TRUE) != FALSE);
}


int MaxsiWindowSystemW32::MsgBox(MaxsiHandle Parent, int Flags, MESTR* ErrorMessage, MESTR* ErrorTitle)
{	
	return MessageBoxM((HWND)Parent, ErrorMessage, ErrorTitle, MB_OK | MB_ICONEXCLAMATION);
}




bool MaxsiControlSystemW32::DeleteControl(MaxsiHandle Control)
{
	return false;
}

MaxsiHandle MaxsiControlSystemW32::CreateFrame(MaxsiHandle Parent)
{
	return NULL;
}

MaxsiHandle MaxsiControlSystemW32::CreateLabel(MaxsiHandle Parent)
{
	return NULL;
}

MaxsiHandle MaxsiControlSystemW32::CreateButton(MaxsiHandle Parent)
{
	return NULL;
}

MaxsiHandle MaxsiControlSystemW32::CreateTextSingleLine(MaxsiHandle Parent)
{
	return NULL;
}

MaxsiHandle MaxsiControlSystemW32::CreateTextMultiLine(MaxsiHandle Parent)
{
	return NULL;
}

MaxsiHandle MaxsiControlSystemW32::CreateRadioButton(MaxsiHandle Parent)
{
	return NULL;
}

MaxsiHandle MaxsiControlSystemW32::CreateCheckButton(MaxsiHandle Parent)
{
	return NULL;
}

MaxsiHandle MaxsiControlSystemW32::CreateProgressBar(MaxsiHandle Parent)
{
	return NULL;
}

MaxsiHandle MaxsiControlSystemW32::CreateTreeView(MaxsiHandle Parent)
{
	return NULL;
}

MaxsiHandle MaxsiControlSystemW32::CreateListView(MaxsiHandle Parent)
{
	return NULL;
}

MaxsiHandle MaxsiControlSystemW32::CreateSeparatorH(MaxsiHandle Parent)
{
	return NULL;
}

bool MaxsiControlSystemW32::SetLabelText(MaxsiHandle Control, MESTR* Text)
{
	return NULL;
}

bool MaxsiControlSystemW32::SetButtonText(MaxsiHandle Control, MESTR* Text)
{
	return NULL;
}

bool MaxsiControlSystemW32::SetProgress(MaxsiHandle Control, float Progress)
{
	return NULL;
}

EndMaxsiNamespace

#endif

